package com.mx.config;

import com.mx.pojo.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    //-----------------被MyMvcConfig调用-----------------------//
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        User loginUser = (User)request.getSession().getAttribute("user");
        if(loginUser==null)
        {
            response.sendRedirect("/login?msg=true");
            return false;
        }

        return true;
    }
}
